package com.example.demo.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.Result;
import com.example.demo.entity.Bom;
import com.example.demo.mapper.BomMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/cc")
public class BomController {
    @Resource
    BomMapper bomMapper;

    @GetMapping
    public String findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "40") Integer pageSize,
                           @RequestParam(defaultValue = "") String search){
        LambdaQueryWrapper<Bom> wrapper = Wrappers.<Bom>lambdaQuery();
        if (StrUtil.isNotBlank(search)){
            wrapper.like(Bom::getPid, search);
        }
        Page<Bom> bomPage = bomMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
        return Result.success(bomMapper.getAll());
    }
}
